package com.yitao.cms.controller.cashCoupon;

import com.skipper.base.bean.DataOutput;
import com.skipper.base.bean.PagedOutput;
import com.yitao.client.constant.cashCoupons.CashCouponsEnums;
import com.yitao.client.dto.cashCoupons.CashCouponsDto;
import com.yitao.client.dto.enums.EnumDto;
import com.yitao.client.dto.product.OperationProductCategoryDto;
import com.yitao.client.dto.shopInfo.ShopQrcodeDto;
import com.yitao.client.model.user.BuyerUserModel;
import com.yitao.cms.constant.UserSession;
import com.yitao.cms.dto.cashCoupons.*;
import com.yitao.cms.model.operationUser.OperationUserCmsModel;
import com.yitao.cms.service.cmsCashCoupons.CmsCashCouponsService;
import com.yitao.cms.service.product.OperationProductCategoryService;
import com.yitao.cms.service.product.ProductCmsService;
import com.yitao.cms.service.shopInfo.ShopQrcodeService;
import com.yitao.cms.utils.DataUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Date: 2020/3/11 11:53
 * @Author: Kien
 */
@Api(value = "/cashCoupon", description = "CMS优惠券列表", tags = {"cms-cashCoupon"})
@RestController
@RequestMapping(value = "/cashCoupon", produces = {"application/json"})
public class CashCouponController {
    @Autowired
    private CmsCashCouponsService cmsCashCouponsService;
    @Autowired
    private ProductCmsService productCmsService;
    @Autowired
    private ShopQrcodeService shopQrcodeService;
    @Autowired
    private OperationProductCategoryService operationProductCategoryService;


    @ApiOperation("新增/编辑优惠券信息")
    @RequestMapping(value = "/saveCashCouponsInfo", method = RequestMethod.POST)
    public DataOutput<CashCouponsDto> save(@RequestBody CashCouponsAddDto cashCouponsAddDto, HttpServletRequest request) {
        return cmsCashCouponsService.saveCashCouponsInfo(cashCouponsAddDto, request);
    }

    @ApiOperation("优惠券信息列表")
    @RequestMapping(value = "/findCashCouponsList", method = RequestMethod.POST)
    public PagedOutput<CashCouponsListDto> findProductInfoList(
            HttpServletRequest request,
            @ApiParam(value = "优惠券名") @RequestParam(value = "couponsName", required = false) String couponsName,
            @ApiParam(value = "分页参数，表示当前页", required = true, defaultValue = "1") @RequestParam(value = "pageNo") Integer pageNo,
            @ApiParam(value = "分页参数，表示每页显示多少条记录", required = true, defaultValue = "10") @RequestParam(value = "pageSize") Integer pageSize
    ) {

        return cmsCashCouponsService.findCashCouponsList(request, couponsName, pageNo, pageSize);
    }

    @ApiOperation("优惠券信息列表->关闭，发布操作")
    @RequestMapping(value = "/updateCashCouponsStatus", method = RequestMethod.POST)
    public DataOutput updateCashCouponsStatus(
            HttpServletRequest request,
            @ApiParam(value = "优惠券id") @RequestParam(value = "couponsId") Long couponsId,
            @ApiParam(value = "优惠券状态(1:未发布 2:发布 3.关闭)") @RequestParam(value = "couponsStatus") Integer couponsStatus
    ) {

        return cmsCashCouponsService.updateCashCouponsStatus(request, couponsId, couponsStatus);
    }

    @ApiOperation("优惠券信息列表->复制操作")
    @RequestMapping(value = "/cashCouponsInfoCopy", method = RequestMethod.POST)
    public DataOutput<CashCouponsDto> cashCouponsInfoCopy(
            HttpServletRequest request,
            @ApiParam(value = "优惠券id") @RequestParam(value = "couponsId") Long couponsId
    ) {
        return cmsCashCouponsService.cashCouponsInfoCopy(request, couponsId);
    }

    @ApiOperation("优惠券信息列表->商品列表(4-14需求)")
    @RequestMapping(value = "/findCashCouponsProductInfoList", method = RequestMethod.POST)
    public PagedOutput<CashCouponsProductListDto> findCashCouponsProductInfoList(
            HttpServletRequest request,
            @ApiParam(value = "运营分类Id") @RequestParam(value = "operationCategoryId", required = false) Long operationCategoryId,
            @ApiParam(value = "商品Id") @RequestParam(value = "productId", required = false) Long productId,
            @ApiParam(value = "商品名") @RequestParam(value = "productName", required = false) String productName,
            @ApiParam(value = "分页参数，表示当前页", required = true, defaultValue = "1") @RequestParam(value = "pageNo") Integer pageNo,
            @ApiParam(value = "分页参数，表示每页显示多少条记录", required = true, defaultValue = "10") @RequestParam(value = "pageSize") Integer pageSize
    ) {
        return productCmsService.findCashCouponsProductInfoList(request, operationCategoryId, productId, DataUtils.Decoder(productName), pageNo, pageSize);
    }

    @ApiOperation("优惠券信息列表->子集运营分类列表(4-14需求)")
    @RequestMapping(value = "/findProductCategorySubsetList", method = RequestMethod.POST)
    public DataOutput<OperationProductCategoryDto> findProductCategorySubsetList(
            HttpServletRequest request
    ) {
        return operationProductCategoryService.findProductCategorySubsetList(request);
    }

    @ApiOperation("优惠券信息列表->优惠券详情")
    @RequestMapping(value = "/cashCouponsInfoDetail", method = RequestMethod.POST)
    public DataOutput<CashCouponsDetailDto> cashCouponsInfoDetail(
            HttpServletRequest request,
            @ApiParam(value = "优惠券id") @RequestParam(value = "couponsId") Long couponsId
    ) {
        return cmsCashCouponsService.cashCouponsInfoDetail(request, couponsId);
    }

    @ApiOperation("优惠券信息列表->推广")
    @RequestMapping(value = "/cashCouponsExpand", method = RequestMethod.POST)
    public DataOutput<CashCouponsExpandDto> cashCouponsExpand(
            HttpServletRequest request,
            @ApiParam(value = "优惠券id") @RequestParam(value = "couponsId") Long couponsId
    ) {
        return cmsCashCouponsService.cashCouponsExpand(request, couponsId);
    }

    @ApiOperation("优惠券信息列表->导出使用订单")
    @RequestMapping(value = "/cashCouponsExportById", method = RequestMethod.GET)
    public void findProductInfoExport(
            HttpServletRequest request, HttpServletResponse response,
            @ApiParam(value = "优惠券id") @RequestParam(value = "couponsId") Long couponsId
    ) throws Exception {
        cmsCashCouponsService.cashCouponsExportById(request, response, couponsId);
    }


    @ApiOperation("优惠券信息列表->发放对象枚举")
    @RequestMapping(value = "/findCouponsUserTypeEnum", method = RequestMethod.POST)
    public DataOutput<EnumDto> findCouponsUserTypeEnum(
    ) {
        return CashCouponsEnums.CouponsUserTypeEnum.getCouponsUserTypeEnum();
    }

    @ApiOperation("优惠券信息列表->发放可用商品枚举")
    @RequestMapping(value = "/findCouponsGoodsTypeEnum", method = RequestMethod.POST)
    public DataOutput<EnumDto> findCouponsGoodsTypeEnum(
    ) {
        return CashCouponsEnums.CouponsGoodsTypeEnum.getCouponsGoodsTypeEnum();
    }

    @ApiOperation("优惠券信息列表->优惠券类型枚举")
    @RequestMapping(value = "/findCouponsTypeEnum", method = RequestMethod.POST)
    public DataOutput<EnumDto> findCouponsTypeEnum(
    ) {
        return CashCouponsEnums.CouponsTypeEnum.getCouponsTypeEnum();
    }

    @ApiOperation("优惠券信息列表->优惠券状态枚举")
    @RequestMapping(value = "/findCouponsStatusEnum", method = RequestMethod.POST)
    public DataOutput<EnumDto> findCouponsStatusEnum(
    ) {
        return CashCouponsEnums.CouponsStatusEnum.getCouponsStatusEnum();
    }

    @ApiOperation("生成二维码图片")
    @RequestMapping(value = "/createQRCode", method = RequestMethod.POST)
    public DataOutput<ShopQrcodeDto> createQRCode(
            HttpServletRequest request,
            @ApiParam(value = "url") @RequestParam(value = "url") String url) {
        return shopQrcodeService.createQRCode(request, url);
    }


}
